
# =====================================
# solve error：UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX
# =====================================
import io
import sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='gb18030') #改变标准输出的默认编码

import requests
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36'
}

kw = {'wd':'中国'}
response = requests.get("http://www.baidu.com/s", headers=headers, params=kw)
print(response)

print(response.text) # 返回unicode格式数据，可能会遇到解码遇到乱码的情况
print(response.content.decode('utf-8'))  # 返回字节流数据
print(response.url)
print(response.encoding)